# -*- coding:utf-8 -*-
class Solution:
    def GetLeastNumbers_Solution(self, tinput, k):
        # write code here
        # if k > len(tinput):
        #     return []
        # else:
        #     return sorted(tinput)[:k]
        if k > len(tinput) or k == 0:
            return []
        res = []
        for i in range(len(tinput)):
            self.sort_res(res, tinput[i])
            print(res)
        return res[:k]

    def sort_res(self,res,item):
        if not res:
            res.append(item)
            return
        res.append(item)
        # print('res append is {}'.format(res))
        j = len(res) - 1
        for i in range(len(res)-2, -1, -1):
            if res[i] <= res[j]:
                break
            else:
                cur = res[i]
                res[i] = res[j]
                res[j] = cur
                j = i
        print(res)


test = Solution()
print(test.GetLeastNumbers_Solution([4,5,1,6,2,7,3,8],4))